<!DOCTYPE HTML>  
<html>  
<head>  
    <meta http-equiv="content-type" content="text/html" />  
    <meta name="author" content="https://github.com/jice1001" />  
    <title>websocket test</title>  
    <script>
		var socket;  
		function Connect(){
			if ("WebSocket" in window)
			{
				try{ 
					var ip = document.getElementById("Conectip").value;
					var ws_ip = "ws://" + ip;
					socket=new WebSocket(ws_ip);  
				}catch(e){  
					alert('error');  
					return;  
				}  
				socket.onopen = sOpen;  
				socket.onerror = sError;
				socket.onmessage= sMessage;
				socket.onclose= sClose;
			} else {
			alert("您的浏览器不支持WebScoket");
			}
		}  
		
		function sOpen(){
			alert('connect success!');
		}
		function sError(e){
			alert("error " + e);
		}
		function sMessage(msg){  
			alert('server says:' + msg.data);
			console.log(msg.data);
		}
		function sClose(e){
			alert("connect closed:" + e.code);
		}  
		function Send(){
			socket.send(document.getElementById("msg").value);
		} 
		function Close(){
			socket.close();
		} 

		function Getinfo()
		{
				var startcmd='{"jsonrpc": "2.0", "method": "DoGetLiveInfo", "params":"", "id": 2}';
				if (socket != null) {
					socket.send( startcmd );
				}   
			
		}
		
		function PullOneStart()
		{
				var pullurl = document.getElementById("msgpullone").value;
				var pullurl_num = document.getElementById("msgpullonenum").value;					
				var startcmd='{"jsonrpc": "2.0", "method": "DoStartPullStream", "params":{"pullurl":"'+pullurl +'","pullurlnum":"'+pullurl_num+'"}, "id": 2}';
				if (socket != null) {
					socket.send( startcmd );
				}
				alert('耐心等待完成!');				
			
		}
		
		
		
		function PullOneStop()
		{
				var pullurl = document.getElementById("msgpullone").value;			
				var startcmd='{"jsonrpc": "2.0", "method": "DoStopPullStream", "params":"'+pullurl +'", "id": 2}';
				if (socket != null) {
					socket.send( startcmd );
				}   
			
		}
		
	
		//----------------------------------------
		function PullTwoStart()
		{
				var pullurl = document.getElementById("msgpulltwo").value;
				var pullurl_num = document.getElementById("msgpulltwonum").value;					
				var startcmd='{"jsonrpc": "2.0", "method": "DoStartPullStream", "params":{"pullurl":"'+pullurl +'","pullurlnum":"'+pullurl_num+'"}, "id": 2}';
				if (socket != null) {
					socket.send( startcmd );
				}   
				alert('耐心等待完成!');	
			
		}
		
		function PullTwoStop()
		{
				var pullurl = document.getElementById("msgpulltwo").value;			
				var startcmd='{"jsonrpc": "2.0", "method": "DoStopPullStream", "params":"'+pullurl +'", "id": 2}';
				if (socket != null) {
					socket.send( startcmd );
				}   
			
		}
		
		function PullThreeStart()
		{
				var pullurl = document.getElementById("msgpullthree").value;			
				var startcmd='{"jsonrpc": "2.0", "method": "DoStartPullStream", "params":{"pullurl":"'+pullurl +'","pullurlnum":"'+1+'"}, "id": 2}';
				if (socket != null) {
					socket.send( startcmd );
				}

				alert('耐心等待完成!');					
			
		}
		function PullThreeStop()
		{
			var pullurl = document.getElementById("msgpullthree").value;			
				var startcmd='{"jsonrpc": "2.0", "method": "DoStopPullStream", "params":"'+pullurl +'", "id": 2}';
				if (socket != null) {
					socket.send( startcmd );
				}   
			
		}
		

		
	</script>
</head>  
   
<body>
<textarea id="Conectip" cols="50">10.10.6.22:9000</textarea>
<br/>
<button id="connect" onClick="Connect();">ConnectWebSocket</button>  
<button id="close" onClick="Close();">CloseWebSocket</button>
<p>&nbsp;</p>

<div id="haha">实例1：不要大批量增加，否则会等待很慢， 建议数量小于10个</div>
<div id="haha">说明：一个海康摄像头最多拉6路RTSP流</div>
<p>
  <textarea id="msgpullone" cols="100" placeholder="请输入rtsp地址" required>rtsp://admin:1234567890e@10.10.7.100:3001/admin</textarea>
  <label id="msg1" cols="5">批量</label>
  <textarea id="msgpullonenum" cols="5">5</textarea>
</p>
<button id="pullonestart" onClick="PullOneStart();">开始拉取</button>  
<button id="pullonestop" onClick="PullOneStop();">停止拉取</button>  
<p>&nbsp;</p>
<div id="haha">实例2：</div>
<p>
  <textarea id="msgpulltwo" cols="100" placeholder="请输入rtsp地址" required>rtsp://192.168.60.53:554/test.sdp</textarea>
   <label id="msg1" cols="5">批量</label>
  <textarea id="msgpulltwonum" cols="5">5</textarea>
</p>
<button id="pulltwostart" onClick="PullTwoStart();">开始拉取</button>  
<button id="pulltwostop" onClick="PullTwoStop();">停止拉取</button>  
<p>&nbsp;</p>

<div id="haha">实例3：</div>
<p>
  <textarea id="msgpullthree" cols="100" placeholder="请输入rtsp地址" required>rtsp://192.168.60.53:554/test.sdp</textarea>
</p>
<button id="pullthreestart" onClick="PullThreeStart();">开始拉取</button>  
<button id="pullthreestop" onClick="PullThreeStop();">停止拉取</button>  
<p>&nbsp;</p>



</body>  
   
</html>  